package com.jp.knowledge.activity;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.fragment.TopicFragment;
import com.jp.knowledge.model.InfoData;
import com.jp.knowledge.model.TopicInfo;

import org.xutils.view.annotation.ViewInject;

/**
 * 话题
 */
public class TopicActivity extends SlidingActivity implements View.OnClickListener {


    //    private ViewPager viewPager;
//    private List<Fragment> fragments;
    private TextView company;//公司
    private TextView topic;//话题 其他

    private String infoId;
    private String topicId;
    private String infoPic;//内容图片
    private String infoTitle;//内容标题   用于下一个详情页面介绍

    private TopicInfo topicInfo;
    private InputMethodManager manager;

    private InfoData infoData;//详情数据

    @ViewInject(R.id.top_return)
    private ImageView returnView;

    @ViewInject(R.id.content)
    private FrameLayout contetnLayout;



    @Override
    protected int getResourceId() {
        return R.layout.activity_topic;
    }

    @Override
    protected void init() {
        topicInfo = getIntent().getParcelableExtra("topicInfo");
        infoData = getIntent().getParcelableExtra("info_bean");
        infoId = getIntent().getStringExtra("infoId");
        topicId = getIntent().getStringExtra("topicId");
        infoPic = getIntent().getStringExtra("info_icon");
        infoTitle = getIntent().getStringExtra("info_title");



//        shadView = findViewById(R.id.shade_view);
//        talkBottom.setShadeView(shadView);
//        shadView.setOnClickListener(this);

        company = (TextView) findViewById(R.id.company);
        topic = (TextView) findViewById(R.id.topic);
        returnView.setOnClickListener(this);
        manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        getSupportFragmentManager().beginTransaction().add(R.id.content, new TopicFragment()).commit();
    }


    public String getInfoPic() {
        return infoPic;
    }

    public String getInfoTitle() {
        return infoTitle;
    }

    public String getInfoId() {
        return infoId;
    }


    public TopicInfo getTopicInfo() {
        return topicInfo;
    }

    public String getTopicId() {
        return topicId;
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.top_return) {
            finish();
        }else if(view.getId()==R.id.shade_view){
//            shadView.setVisibility(View.GONE);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {
                manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
        return super.onTouchEvent(event);
    }

    public InfoData getInfoData() {
        return infoData;
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
//        ToasUtil.toast(context,"你按了返回");
    }
}
